package com.pengshun.modules.api.statistical.service.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author luoligang
 * @create 2021/1/26
 */
@Data
public class YearStatistical {

    private Integer year;
    private  List<CoalStatisticalDto> coalStatisticalDtos;
    private BigDecimal bigPrice;
    private BigDecimal smallPrice;
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private String priceDate;
    private String color;

    public String getPriceDate() {
        if(this.year!=null&&this.year.toString().length()==8){
            priceDate=this.year.toString().substring(0,4)+"-"+this.year.toString().substring(4,6)+"-"+this.year.toString().substring(6,8);
        }
        return priceDate;
    }

    public BigDecimal getBigPrice() {
        BigDecimal temp=new BigDecimal(0);
        if(this.coalStatisticalDtos.size()>0){
            for(CoalStatisticalDto dto:coalStatisticalDtos){
                if(dto.getNowPrice()!=null){
                    if(dto.getNowPrice().compareTo(temp)==1){
                        temp=dto.getNowPrice();
                    }
                }
            }
        }
        return temp;
    }

    public BigDecimal getSmallPrice() {
        BigDecimal temp=new BigDecimal(9999999);
        if(this.coalStatisticalDtos.size()>0){
            for(CoalStatisticalDto dto:coalStatisticalDtos){
                if(dto.getNowPrice()!=null){
                    if(dto.getNowPrice().compareTo(temp)==-1){
                        temp=dto.getNowPrice();
                    }
                }
            }
        }
        return temp;
    }
}
